//
// AddressSpace.h
// Usage: Manage user address space
// CreateDate: 2009-05-03
// Author: MaJiuyue
//
#ifndef _ADDRESS_SPACE_H_
#define _ADDRESS_SPACE_H_

#include <NewLife.h>
#include <sys/types.h>

class AddressSpace
{
private:
	// User heap
	addr_t m_HeapStart;
	addr_t m_HeapEnd;

	// User stack
	addr_t m_StackBase;
	addr_t m_StackTop;

public:
	AddressSpace(addr_t HeapStart, addr_t StackBase);
	AddressSpace(const AddressSpace & target);
	~AddressSpace();

public:
	// Extend heap, return start address of extend heap, if overflow panic
	addr_t ExtendHeap(int incr);
	// Extend stack, if overflow panic
	void ExtendStack(int incr);
	// Check if addr is available
	bool IsContain(addr_t addr);

	addr_t AllocUser(size_t size);
	void DeallocUser(addr_t vaddr, size_t size);
};

#endif

